<template>
  <div>
    <!--  面包屑导航区-->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>管理员管理</el-breadcrumb-item>
    <el-breadcrumb-item>管理员列表</el-breadcrumb-item>
  </el-breadcrumb>

  <!--  卡片视图区-->
  <el-card>
<!--    搜索与添加区域-->

    <el-row :gutter="20">
      <el-col :span="12">
        <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getUsersList">
          <el-button slot="append" icon="el-icon-search" @click="searchUser"></el-button>
        </el-input>
      </el-col>
      <el-col :span="6">
        <el-button type="primary" @click="addDialogVisible = true">添加用户</el-button>
      </el-col>
    </el-row>
    <el-table :data="usersList" border stripe>
      <el-table-column label="ID" type="index"></el-table-column>
      <el-table-column label="名称" prop="username"></el-table-column>
      <el-table-column label="性别" prop="gender"></el-table-column>
      <!-- <el-table-column label="密码" prop="password"></el-table-column> -->
      <el-table-column label="电话" prop="mobile"></el-table-column>
      <!-- <el-table-column label="角色" prop="role_name"></el-table-column> -->
      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status" @change="userStatusChange(scope.row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="120px">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditDialog(scope.row.id)"></el-button>
          <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeUser(scope.row.id)"></el-button>

          <!-- <el-tooltip content="分配角色" placement="top" :enterable="false">
            <el-button type="warning" icon="el-icon-setting" size="mini" @click="setRole(scope.row)"></el-button>
          </el-tooltip> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[1, 2, 4, 5]"
      :page-size="this.queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="this.total">
    </el-pagination>
  </el-card>
  </div>
</template>

<script>
export default {
  name: 'Admins',
  components: {

  },
  //生命周期函数
    created() {
      this.getAdminsList();
    },
    methods: {
      // 获取用户列表
      async getAdminsList() {
        const {data: res} = await this.$http.get('admin/list');
        if (res.status !== 200) {
          return this.$message.error('获取管理员列表失败')
        }
        // 将用户状态由0、1改为ture、false
        res.data.forEach((v,i)=>{
          if(v.status === 0) {
            v.status = true
            this.usersList.push(v)
          }else {
            v.status = false
            this.usersList.push(v)
          }
        });
        this.total = res.data.total;
      }
    }
}
</script>

<style>

</style>
